package com;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.dao.support.DaoSupport;
/**      
	 * @author: zhangxubin  
	 * @date: 2019年3月28日 下午2:45:31 
	 * @Description mybatis-spring-1.3.2中取消了自动注入SqlSessionFactory 
	 * 和 SqlSessionTemplate，所以会报出Property ‘sqlSessionFactory’ or ‘sqlSessionTemplate’ 
	 * are required错误。
	 */
public class SqlSessionDaoSupport extends DaoSupport {
	
	private SqlSession sqlSession;
	
	private boolean  externalSqlSession;

	@Override
	protected void checkDaoConfig() throws IllegalArgumentException {
		// TODO Auto-generated method stub
		
	}
	 public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
		    if (!this.externalSqlSession) {
		      this.sqlSession = new SqlSessionTemplate(sqlSessionFactory);
		    }
		  }

		  public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
		    this.sqlSession = sqlSessionTemplate;
		    this.externalSqlSession = true;
		  }
	
	
}
